home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 March / Pc Users extra 6.iso / pshare95 / prog / formula1 / vcform1.z / format2.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-09-19  |  29.9 KB  |  846 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Palette Maker"
  4.    ClientHeight    =   5070
  5.    ClientLeft      =   750
  6.    ClientTop       =   1470
  7.    ClientWidth     =   9690
  8.    Height          =   5475
  9.    Icon            =   "format2.frx":0000
  10.    Left            =   690
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5070
  13.    ScaleWidth      =   9690
  14.    Top             =   1125
  15.    Width           =   9810
  16.    Begin VB.Frame Frame3 
  17.       Caption         =   "  Generate Palette  "
  18.       Height          =   2655
  19.       Left            =   180
  20.       TabIndex        =   18
  21.       Top             =   2280
  22.       Width           =   4215
  23.       Begin VB.CommandButton cmdGenPalette 
  24.          Caption         =   "Generate"
  25.          Height          =   315
  26.          Left            =   60
  27.          TabIndex        =   33
  28.          Top             =   2160
  29.          Width           =   795
  30.       End
  31.       Begin Threed.SSPanel SSPanel3 
  32.          Height          =   1935
  33.          Left            =   3060
  34.          TabIndex        =   30
  35.          Top             =   540
  36.          Width           =   975
  37.          _Version        =   65536
  38.          _ExtentX        =   1720
  39.          _ExtentY        =   3413
  40.          _StockProps     =   15
  41.          BackColor       =   12632256
  42.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  43.             Name            =   "MS Sans Serif"
  44.             Size            =   8.25
  45.             Charset         =   0
  46.             Weight          =   400
  47.             Underline       =   0   'False
  48.             Italic          =   0   'False
  49.             Strikethrough   =   0   'False
  50.          EndProperty
  51.          BevelOuter      =   1
  52.          Begin VB.OptionButton optBDelta 
  53.             Caption         =   "Bell"
  54.             Height          =   255
  55.             Index           =   3
  56.             Left            =   120
  57.             TabIndex        =   45
  58.             Top             =   1620
  59.             Width           =   795
  60.          End
  61.          Begin VB.OptionButton optBDelta 
  62.             Caption         =   "1/Log"
  63.             Height          =   255
  64.             Index           =   2
  65.             Left            =   120
  66.             TabIndex        =   44
  67.             Top             =   1380
  68.             Width           =   795
  69.          End
  70.          Begin VB.OptionButton optBDelta 
  71.             Caption         =   "Log"
  72.             Height          =   255
  73.             Index           =   1
  74.             Left            =   120
  75.             TabIndex        =   43
  76.             Top             =   1140
  77.             Width           =   795
  78.          End
  79.          Begin VB.OptionButton optBDelta 
  80.             Caption         =   "Linear"
  81.             Height          =   255
  82.             Index           =   0
  83.             Left            =   120
  84.             TabIndex        =   42
  85.             Top             =   900
  86.             Value           =   -1  'True
  87.             Width           =   795
  88.          End
  89.          Begin VB.TextBox txtFrom 
  90.             Alignment       =   1  'Right Justify
  91.             Height          =   285
  92.             Index           =   2
  93.             Left            =   240
  94.             TabIndex        =   32
  95.             Text            =   "0"
  96.             Top             =   120
  97.             Width           =   555
  98.          End
  99.          Begin VB.TextBox TxtTo 
  100.             Alignment       =   1  'Right Justify
  101.             Height          =   285
  102.             Index           =   2
  103.             Left            =   240
  104.             TabIndex        =   31
  105.             Text            =   "255"
  106.             Top             =   480
  107.             Width           =   555
  108.          End
  109.       End
  110.       Begin Threed.SSPanel SSPanel2 
  111.          Height          =   1935
  112.          Left            =   1980
  113.          TabIndex        =   27
  114.          Top             =   540
  115.          Width           =   975
  116.          _Version        =   65536
  117.          _ExtentX        =   1720
  118.          _ExtentY        =   3413
  119.          _StockProps     =   15
  120.          BackColor       =   12632256
  121.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  122.             Name            =   "MS Sans Serif"
  123.             Size            =   8.25
  124.             Charset         =   0
  125.             Weight          =   400
  126.             Underline       =   0   'False
  127.             Italic          =   0   'False
  128.             Strikethrough   =   0   'False
  129.          EndProperty
  130.          BevelOuter      =   1
  131.          Begin VB.OptionButton optGDelta 
  132.             Caption         =   "Bell"
  133.             Height          =   255
  134.             Index           =   3
  135.             Left            =   120
  136.             TabIndex        =   41
  137.             Top             =   1620
  138.             Width           =   735
  139.          End
  140.          Begin VB.OptionButton optGDelta 
  141.             Caption         =   "1/Log"
  142.             Height          =   255
  143.             Index           =   2
  144.             Left            =   120
  145.             TabIndex        =   40
  146.             Top             =   1380
  147.             Width           =   735
  148.          End
  149.          Begin VB.OptionButton optGDelta 
  150.             Caption         =   "Log"
  151.             Height          =   255
  152.             Index           =   1
  153.             Left            =   120
  154.             TabIndex        =   39
  155.             Top             =   1140
  156.             Width           =   735
  157.          End
  158.          Begin VB.OptionButton optGDelta 
  159.             Caption         =   "Linear"
  160.             Height          =   255
  161.             Index           =   0
  162.             Left            =   120
  163.             TabIndex        =   38
  164.             Top             =   900
  165.             Value           =   -1  'True
  166.             Width           =   735
  167.          End
  168.          Begin VB.TextBox txtFrom 
  169.             Alignment       =   1  'Right Justify
  170.             Height          =   285
  171.             Index           =   1
  172.             Left            =   240
  173.             TabIndex        =   29
  174.             Text            =   "0"
  175.             Top             =   120
  176.             Width           =   555
  177.          End
  178.          Begin VB.TextBox TxtTo 
  179.             Alignment       =   1  'Right Justify
  180.             Height          =   285
  181.             Index           =   1
  182.             Left            =   240
  183.             TabIndex        =   28
  184.             Text            =   "255"
  185.             Top             =   480
  186.             Width           =   555
  187.          End
  188.       End
  189.       Begin Threed.SSPanel SSPanel1 
  190.          Height          =   1935
  191.          Left            =   900
  192.          TabIndex        =   24
  193.          Top             =   540
  194.          Width           =   975
  195.          _Version        =   65536
  196.          _ExtentX        =   1720
  197.          _ExtentY        =   3413
  198.          _StockProps     =   15
  199.          BackColor       =   12632256
  200.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  201.             Name            =   "MS Sans Serif"
  202.             Size            =   8.25
  203.             Charset         =   0
  204.             Weight          =   400
  205.             Underline       =   0   'False
  206.             Italic          =   0   'False
  207.             Strikethrough   =   0   'False
  208.          EndProperty
  209.          BevelOuter      =   1
  210.          Begin VB.OptionButton optRDelta 
  211.             Caption         =   "Bell"
  212.             Height          =   255
  213.             Index           =   3
  214.             Left            =   120
  215.             TabIndex        =   37
  216.             Top             =   1620
  217.             Width           =   735
  218.          End
  219.          Begin VB.OptionButton optRDelta 
  220.             Caption         =   "1/Log"
  221.             Height          =   255
  222.             Index           =   2
  223.             Left            =   120
  224.             TabIndex        =   36
  225.             Top             =   1380
  226.             Width           =   735
  227.          End
  228.          Begin VB.OptionButton optRDelta 
  229.             Caption         =   "Log"
  230.             Height          =   255
  231.             Index           =   1
  232.             Left            =   120
  233.             TabIndex        =   35
  234.             Top             =   1140
  235.             Width           =   735
  236.          End
  237.          Begin VB.OptionButton optRDelta 
  238.             Caption         =   "Linear"
  239.             Height          =   255
  240.             Index           =   0
  241.             Left            =   120
  242.             TabIndex        =   34
  243.             Top             =   900
  244.             Value           =   -1  'True
  245.             Width           =   735
  246.          End
  247.          Begin VB.TextBox txtFrom 
  248.             Alignment       =   1  'Right Justify
  249.             Height          =   285
  250.             Index           =   0
  251.             Left            =   240
  252.             TabIndex        =   26
  253.             Text            =   "0"
  254.             Top             =   120
  255.             Width           =   555
  256.          End
  257.          Begin VB.TextBox TxtTo 
  258.             Alignment       =   1  'Right Justify
  259.             Height          =   285
  260.             Index           =   0
  261.             Left            =   240
  262.             TabIndex        =   25
  263.             Text            =   "255"
  264.             Top             =   480
  265.             Width           =   555
  266.          End
  267.       End
  268.       Begin VB.Label Label2 
  269.          Alignment       =   1  'Right Justify
  270.          Caption         =   "To:"
  271.          Height          =   195
  272.          Index           =   1
  273.          Left            =   300
  274.          TabIndex        =   23
  275.          Top             =   1080
  276.          Width           =   435
  277.       End
  278.       Begin VB.Label Label1 
  279.          Alignment       =   2  'Center
  280.          Caption         =   "Blue"
  281.          Height          =   195
  282.          Index           =   5
  283.          Left            =   3300
  284.          TabIndex        =   22
  285.          Top             =   300
  286.          Width           =   555
  287.       End
  288.       Begin VB.Label Label1 
  289.          Alignment       =   2  'Center
  290.          Caption         =   "Green"
  291.          Height          =   195
  292.          Index           =   4
  293.          Left            =   2220
  294.          TabIndex        =   21
  295.          Top             =   300
  296.          Width           =   555
  297.       End
  298.       Begin VB.Label Label1 
  299.          Alignment       =   2  'Center
  300.          Caption         =   "Red"
  301.          Height          =   195
  302.          Index           =   3
  303.          Left            =   1140
  304.          TabIndex        =   20
  305.          Top             =   300
  306.          Width           =   555
  307.       End
  308.       Begin VB.Label Label2 
  309.          Alignment       =   1  'Right Justify
  310.          Caption         =   "From:"
  311.          Height          =   195
  312.          Index           =   0
  313.          Left            =   240
  314.          TabIndex        =   19
  315.          Top             =   660
  316.          Width           =   495
  317.       End
  318.    End
  319.    Begin VB.Frame Frame2 
  320.       Caption         =   " Cell Colors "
  321.       Height          =   1155
  322.       Left            =   4560
  323.       TabIndex        =   7
  324.       Top             =   2400
  325.       Width           =   3375
  326.       Begin VB.TextBox txtColor 
  327.          Alignment       =   1  'Right Justify
  328.          Height          =   285
  329.          Index           =   0
  330.          Left            =   300
  331.          TabIndex        =   10
  332.          Text            =   "255"
  333.          Top             =   630
  334.          Width           =   495
  335.       End
  336.       Begin VB.TextBox txtColor 
  337.          Alignment       =   1  'Right Justify
  338.          Height          =   285
  339.          Index           =   1
  340.          Left            =   1320
  341.          TabIndex        =   9
  342.          Text            =   "255"
  343.          Top             =   630
  344.          Width           =   495
  345.       End
  346.       Begin VB.TextBox txtColor 
  347.          Alignment       =   1  'Right Justify
  348.          Height          =   285
  349.          Index           =   2
  350.          Left            =   2340
  351.          TabIndex        =   8
  352.          Text            =   "255"
  353.          Top             =   630
  354.          Width           =   495
  355.       End
  356.       Begin VB.Label Label1 
  357.          Alignment       =   2  'Center
  358.          Caption         =   "Red"
  359.          Height          =   195
  360.          Index           =   0
  361.          Left            =   300
  362.          TabIndex        =   16
  363.          Top             =   360
  364.          Width           =   555
  365.       End
  366.       Begin VB.Label Label1 
  367.          Alignment       =   2  'Center
  368.          Caption         =   "Green"
  369.          Height          =   195
  370.          Index           =   1
  371.          Left            =   1320
  372.          TabIndex        =   15
  373.          Top             =   360
  374.          Width           =   555
  375.       End
  376.       Begin VB.Label Label1 
  377.          Alignment       =   2  'Center
  378.          Caption         =   "Blue"
  379.          Height          =   195
  380.          Index           =   2
  381.          Left            =   2340
  382.          TabIndex        =   14
  383.          Top             =   360
  384.          Width           =   555
  385.       End
  386.       Begin Spin.SpinButton spnColor 
  387.          Height          =   345
  388.          Index           =   0
  389.          Left            =   840
  390.          TabIndex        =   13
  391.          Top             =   600
  392.          Width           =   225
  393.          _Version        =   65536
  394.          _ExtentX        =   397
  395.          _ExtentY        =   609
  396.          _StockProps     =   73
  397.          Delay           =   100
  398.          ShadowThickness =   1
  399.          TdThickness     =   1
  400.       End
  401.       Begin Spin.SpinButton spnColor 
  402.          Height          =   345
  403.          Index           =   1
  404.          Left            =   1860
  405.          TabIndex        =   12
  406.          Top             =   600
  407.          Width           =   225
  408.          _Version        =   65536
  409.          _ExtentX        =   397
  410.          _ExtentY        =   609
  411.          _StockProps     =   73
  412.          Delay           =   100
  413.          ShadowThickness =   1
  414.          TdThickness     =   1
  415.       End
  416.       Begin Spin.SpinButton spnColor 
  417.          Height          =   345
  418.          Index           =   2
  419.          Left            =   2880
  420.          TabIndex        =   11
  421.          Top             =   600
  422.          Width           =   225
  423.          _Version        =   65536
  424.          _ExtentX        =   397
  425.          _ExtentY        =   609
  426.          _StockProps     =   73
  427.          Delay           =   100
  428.          ShadowThickness =   1
  429.          TdThickness     =   1
  430.       End
  431.    End
  432.    Begin VB.Frame Frame1 
  433.       Caption         =   " Display "
  434.       Height          =   1155
  435.       Left            =   4560
  436.       TabIndex        =   2
  437.       Top             =   3660
  438.       Width           =   3375
  439.       Begin VB.ComboBox cboPalette 
  440.          Height          =   300
  441.          ItemData        =   "format2.frx":044A
  442.          Left            =   1860
  443.          List            =   "format2.frx":044C
  444.          Style           =   2  'Dropdown List
  445.          TabIndex        =   17
  446.          Top             =   300
  447.          Width           =   1335
  448.       End
  449.       Begin VB.CommandButton cmdRefreshPalette 
  450.          Caption         =   "Refresh Palette"
  451.          Height          =   315
  452.          Left            =   1860
  453.          TabIndex        =   6
  454.          Top             =   720
  455.          Width           =   1335
  456.       End
  457.       Begin VB.OptionButton optDecimal 
  458.          Caption         =   "As Decimal"
  459.          Height          =   255
  460.          Left            =   540
  461.          TabIndex        =   4
  462.          Top             =   480
  463.          Value           =   -1  'True
  464.          Width           =   1155
  465.       End
  466.       Begin VB.OptionButton optHex 
  467.          Caption         =   "As Hex"
  468.          Height          =   195
  469.          Left            =   540
  470.          TabIndex        =   3
  471.          Top             =   780
  472.          Width           =   1035
  473.       End
  474.       Begin Threed.SSCheck chkShowNumbers 
  475.          Height          =   255
  476.          Left            =   240
  477.          TabIndex        =   5
  478.          Top             =   240
  479.          Width           =   1515
  480.          _Version        =   65536
  481.          _ExtentX        =   2672
  482.          _ExtentY        =   450
  483.          _StockProps     =   78
  484.          Caption         =   "Show Numbers"
  485.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  486.             Name            =   "MS Sans Serif"
  487.             Size            =   8.25
  488.             Charset         =   0
  489.             Weight          =   400
  490.             Underline       =   0   'False
  491.             Italic          =   0   'False
  492.             Strikethrough   =   0   'False
  493.          EndProperty
  494.          Value           =   -1  'True
  495.       End
  496.    End
  497.    Begin VB.TextBox txtFileName 
  498.       Height          =   285
  499.       Left            =   8220
  500.       TabIndex        =   1
  501.       Text            =   "MyPalet1.txt"
  502.       Top             =   4320
  503.       Width           =   1215
  504.    End
  505.    Begin VB.CommandButton cmdSaveAs 
  506.       Caption         =   "Save As"
  507.       Height          =   345
  508.       Left            =   8220
  509.       TabIndex        =   0
  510.       Top             =   3840
  511.       Width           =   1215
  512.    End
  513.    Begin VCF150Ctl.F1Book F1Book1 
  514.       Height          =   2115
  515.       Left            =   180
  516.       TabIndex        =   46
  517.       Top             =   120
  518.       Width           =   9255
  519.       _ExtentX        =   16325
  520.       _ExtentY        =   3731
  521.       _0              =   $"format2.frx":044E
  522.       _1              =   $"format2.frx":0853
  523.       _2              =   $"format2.frx":0C58
  524.       _3              =   $"format2.frx":105C
  525.       _4              =   $"format2.frx":1461
  526.       _count          =   5
  527.       _ver            =   1
  528.    End
  529. Attribute VB_Name = "Form1"
  530. Attribute VB_Creatable = False
  531. Attribute VB_Exposed = False
  532. '' Format2 - a portable palette generator for Formula One 3.0 OCX
  533. '' Description:
  534. ''    Allows you to view and alter a palette and then save the entries
  535. ''    as VB code that you can later load into a project as a module to
  536. ''    setup a custom palette. The palette is layed out as it appears in
  537. ''    the custom color combo boxes (as on the FormatPatternDlg).
  538. ''    The Formula One palette was designed with Excel compatibility in
  539. ''    mind. The Excel palette has several (8) entries that are duplicates
  540. ''    and can be improved upon for several situations. One is color
  541. ''    coordinating a First Impression Chart with Formula One patterns.
  542. ''    The Palette1 module was extracted from First Impression. Now that
  543. ''    live charts can easily be placed on a Workbook, you can format your
  544. ''    data to match chart series colors or even data point colors.
  545. ''    This project also illustrates how handy Formula One can be as a programming
  546. ''    aid. For instance, I constructed the code in the Palette1 module by
  547. ''    copying the RGB values from First Impression into columns A, B, and C
  548. ''    of a Formula One Workbook. In cell D1 I placed the formula
  549. ''       =".PaletteEntry(" & ROW() & ") = RGB(" & A1 & "," & B1 & "," C1 & ")"
  550. ''    and then copied that formula down to row 63. I then removed a couple
  551. ''    of colors since the First Impression palette has more entries than
  552. ''    the Formula One palette. This was simple since the palette entries
  553. ''    were automatically fixed up when the row was deleted. Next, cut and paste
  554. ''    into the VB code window which again saved much typing. Another way Formula
  555. ''    One is used is as a text formatter. When you save a file in this
  556. ''    project, the code is placed in Formula One and saved as a text file.
  557. ''    Why use this? Often it is hard to get just the right look for the finished
  558. ''    project. You want just the right colors and patterns for your formatting
  559. ''    and spend a lot of time getting that look. This doesn't have much to do
  560. ''    with the problem solving you are doing but in many cases is as important.
  561. ''    Often you will find colors that suit you and want to use them over.
  562. ''    This project provides a little different way of creating a palette but
  563. ''    more importantly, allows you to save your work and easily reuse it. This
  564. ''    allows you to spend more time on the important code - the code that solves
  565. ''    the problem. If you build a collection of these reusable modules, you can
  566. ''    leave a lot of the UI till the end and then easliy and quickly change it
  567. ''    to suit customer desires.
  568. Option Explicit
  569. Private Sub cboPalette_Click()
  570.    Select Case cboPalette.ListIndex
  571.       Case 0:
  572.          Call ChangeToPalette1(F1Book1)
  573.       Case 1:
  574.          Call ChangeToPalette2(F1Book1)
  575.       Case 2:
  576.          Call ChangeToPalette3(F1Book1)
  577.       Case 3:
  578.          Call ChangeToPalette4(F1Book1)
  579.       Case 4:
  580.          Call ChangeToPalette5(F1Book1)
  581.       Case 5:
  582.          Call ChangeToPalette6(F1Book1)
  583.       Case 6:
  584.          Call ChangeToPalette7(F1Book1)
  585.    End Select
  586.    Call cmdRefreshPalette_Click
  587. End Sub
  588. Private Sub chkShowNumbers_Click(Value As Integer)
  589.    optDecimal.Enabled = Value
  590.    optHex.Enabled = Value
  591.    Call cmdRefreshPalette_Click
  592. End Sub
  593. Private Sub cmdGenPalette_Click()
  594. '' Uses settings in the Generate Palette Frame to set the
  595. '' Formula One palette. First two entries are always
  596. '' Black and white.
  597.    Const kLINEAR = 0
  598.    Const kLOG = 1
  599.    Const kILOG = 2
  600.    Const kBELL = 3
  601.    Dim rmin%, rmax%, gmin%, gmax%, bmin%, bmax%
  602.    Dim rval%, gval%, bval%
  603.    Dim rType%, gType%, bType%
  604.    Dim i%
  605.    rmin = Val(txtFrom(0).Text)
  606.    gmin = Val(txtFrom(1).Text)
  607.    bmin = Val(txtFrom(2).Text)
  608.    rmax = Val(TxtTo(0).Text)
  609.    gmax = Val(TxtTo(1).Text)
  610.    bmax = Val(TxtTo(2).Text)
  611.    If optRDelta(0).Value = True Then rType = kLINEAR
  612.    If optRDelta(1).Value = True Then rType = kLOG
  613.    If optRDelta(2).Value = True Then rType = kILOG
  614.    If optRDelta(3).Value = True Then rType = kBELL
  615.    If optGDelta(0).Value = True Then gType = kLINEAR
  616.    If optGDelta(1).Value = True Then gType = kLOG
  617.    If optGDelta(2).Value = True Then gType = kILOG
  618.    If optGDelta(3).Value = True Then gType = kBELL
  619.    If optBDelta(0).Value = True Then bType = kLINEAR
  620.    If optBDelta(1).Value = True Then bType = kLOG
  621.    If optBDelta(2).Value = True Then bType = kILOG
  622.    If optBDelta(3).Value = True Then bType = kBELL
  623.    With F1Book1
  624.       .PaletteEntry(1) = 0
  625.       .PaletteEntry(2) = RGB(255, 255, 255)
  626.       For i = 3 To 56
  627.          Select Case rType
  628.             Case kLINEAR:
  629.                rval = ((i / 56) * (rmax - rmin)) + rmin
  630.             Case kLOG:
  631.                rval = ((Log((i / 56) * 4)) * (rmax - rmin)) + rmin
  632.             Case kILOG:
  633.                rval = ((1 / (Log((i / 56) * 35))) * (rmax - rmin)) + rmin
  634.             Case kBELL:
  635.                rval = (Sin((i / 56) * 3.14) * (rmax - rmin)) + rmin
  636.          End Select
  637.          
  638.          Select Case gType
  639.             Case kLINEAR:
  640.                gval = ((i / 56) * (gmax - gmin)) + gmin
  641.             Case kLOG:
  642.                gval = ((Log((i / 56) * 4)) * (gmax - gmin)) + gmin
  643.             Case kILOG:
  644.                gval = ((1 / (Log((i / 56) * 35))) * (gmax - gmin)) + gmin
  645.          End Select
  646.          
  647.          Select Case bType
  648.             Case kLINEAR:
  649.                bval = ((i / 56) * (bmax - bmin)) + bmin
  650.             Case kLOG:
  651.                bval = ((Log((i / 56) * 4)) * (bmax - bmin)) + bmin
  652.             Case kILOG:
  653.                bval = ((1 / (Log((i / 56) * 35))) * (bmax - bmin)) + bmin
  654.          End Select
  655.          
  656.          .PaletteEntry(i) = RGB(Abs(rval), Abs(gval), Abs(bval))
  657.       Next i
  658.       
  659.    End With
  660.    Call cmdRefreshPalette_Click
  661. End Sub
  662. Private Sub cmdRefreshPalette_Click()
  663.    Dim i&, j&
  664.    With F1Book1
  665.       If chkShowNumbers.Value = False Then .ClearRange 1, 1, 7, 8, F1ClearAll
  666.       For j = 1 To 8
  667.          For i = 1 To 7
  668.             .SetSelection i, j, i, j
  669.             .SetPattern 1, .PaletteEntry(j + ((i - 1) * 8)), 0
  670.             If chkShowNumbers.Value = True Then
  671.                If optDecimal.Value = True Then
  672.                   .NumberRC(i, j) = .PaletteEntry(j + ((i - 1) * 8))
  673.                Else
  674.                   .TextRC(i, j) = Hex(.PaletteEntry(j + ((i - 1) * 8)))
  675.                End If
  676.             End If
  677.          Next i
  678.       Next j
  679.    End With
  680. End Sub
  681. Private Sub cmdSaveAs_Click()
  682. '' Formula One will not refresh the screen until we exit
  683. '' this procedure so we will write on it, save the file
  684. '' and then refresh the palette. Error checking is left
  685. '' as an exercise to the reader. The code uses numbers
  686. '' instead of the RGB function for speed. You can always
  687. '' add your saved palette back into this project to edit
  688. '' later.
  689.    On Error GoTo FileWriteError
  690.    Dim i&
  691.    With F1Book1
  692.       .ClearRange -1, -1, -1, -1, F1ClearAll
  693.       .TextRC(1, 1) = "Option Explicit"
  694.       .TextRC(3, 1) = "Sub " & Left$(txtFileName.Text, Len(txtFileName.Text) - 4) & "()"
  695.       .TextRC(5, 2) = "With F1Book1"
  696.       For i = 1 To 56
  697.          .TextRC(i + 6, 3) = ".PaletteEntry(" & i & ") = " & .PaletteEntry(i)
  698.       Next i
  699.       .TextRC(64, 2) = "End With"
  700.       .TextRC(65, 1) = "End Sub"
  701.       .Write App.Path & "\" & txtFileName.Text, F1FileTabbedText
  702.       '' Now set right alignment so the hex numbers look good
  703.       .SetSelection -1, -1, -1, -1
  704.       .SetAlignment F1HAlignRight, False, F1VAlignBottom, 0
  705.       .Selection = "A1"
  706.    End With
  707.    Call cmdRefreshPalette_Click
  708.    Exit Sub
  709. FileWriteError:
  710.    MsgBox Error
  711. End Sub
  712. Private Sub optDecimal_Click()
  713.    Call cmdRefreshPalette_Click
  714. End Sub
  715. Private Sub optHex_Click()
  716.    Call cmdRefreshPalette_Click
  717. End Sub
  718. Private Sub F1Book1_Click(ByVal nRow As Long, ByVal nCol As Long)
  719. '' Gets the palette entry associated with a cell, cracks it
  720. '' into RGB and puts it in the color text boxes
  721.    Dim r%, g%, b%, color&
  722.    If nRow > 0 And nCol > 0 Then    ' Ignore the col and row hdr clicks
  723.       color = F1Book1.PaletteEntry(nCol + ((nRow - 1) * 8))
  724.       Call CrackColor(color, r, g, b)
  725.       txtColor(0).Text = Str$(r)
  726.       txtColor(1).Text = Str$(g)
  727.       txtColor(2).Text = Str$(b)
  728.    End If
  729. End Sub
  730. Private Sub Form_Load()
  731.    F1Book1.Width = 9540
  732.    F1Book1.Height = 2070
  733.    Call cmdRefreshPalette_Click
  734.    cboPalette.AddItem "First Impression"
  735.    cboPalette.AddItem "Ochres"
  736.    cboPalette.AddItem "Yellow-Greens"
  737.    cboPalette.AddItem "Magentas"
  738.    cboPalette.AddItem "Blues"
  739.    cboPalette.AddItem "Cyan-Greens"
  740.    cboPalette.AddItem "Cyan-Blues"
  741. End Sub
  742. Sub CrackColor(color&, r%, g%, b%)
  743. '' Breaks a long color into its component parts and returns
  744. '' in r, g, and b. Note that the ColorRef stores the color
  745. '' in 3 low order bytes as BGR. The hex function does not
  746. '' pad with zeroes so we use a select.
  747.    Dim colorStr$, rStr$, gStr$, bStr$
  748.    Let colorStr = Hex(color)
  749.    Select Case Len(colorStr)
  750.       Case 1, 2:
  751.          r = Val("&H" & colorStr)
  752.          g = 0
  753.          b = 0
  754.       Case 3:
  755.          r = Val("&H" & Right$(colorStr, 2))
  756.          g = Val("&H" & Left$(colorStr, 1))
  757.          b = 0
  758.       Case 4:
  759.          r = Val("&H" & Right$(colorStr, 2))
  760.          g = Val("&H" & Left$(colorStr, 2))
  761.          b = 0
  762.       Case 5:
  763.          r = Val("&H" & Right$(colorStr, 2))
  764.          g = Val("&H" & Mid$(colorStr, 2, 2))
  765.          b = Val("&H" & Left$(colorStr, 1))
  766.       Case 6:
  767.          r = Val("&H" & Right$(colorStr, 2))
  768.          g = Val("&H" & Mid$(colorStr, 3, 2))
  769.          b = Val("&H" & Left$(colorStr, 2))
  770.    End Select
  771. End Sub
  772. Private Sub mnuCopy_Click()
  773.    F1Book1.Write App.Path & "\foo.txt", F1FileExcel5
  774. End Sub
  775. Private Sub spnColor_SpinDown(Index As Integer)
  776. '' Decrements the text box value and applies the new
  777. '' color to the palette entry corresponding to the selected
  778. '' cell in the worksheet. Decimals will appear to jump
  779. '' wildly. Use Hex view if you want them to increment
  780. '' smoothly.
  781.    Dim num%
  782.    num = Val(txtColor(Index).Text) - 1
  783.    If num > -1 Then
  784.       txtColor(Index).Text = Str$(num)
  785.       Call SetColor
  786.    End If
  787. End Sub
  788. Private Sub spnColor_SpinUp(Index As Integer)
  789. '' Increments the text box value and applies the new
  790. '' color to the palette entry corresponding to the selected
  791. '' cell in the worksheet. Decimals will appear to jump
  792. '' wildly. Use Hex view if you want them to increment
  793. '' smoothly.
  794.    Dim num%
  795.    num = Val(txtColor(Index).Text) + 1
  796.    If num < 256 Then
  797.       txtColor(Index).Text = Str$(num)
  798.       Call SetColor
  799.    End If
  800. End Sub
  801. Sub SetColor()
  802.    Dim pNum&
  803.    With F1Book1
  804.       pNum = .SelStartCol + ((.SelStartRow - 1) * 8)
  805.       .PaletteEntry(pNum) = RGB(Val(txtColor(0).Text), Val(txtColor(1).Text), Val(txtColor(2).Text))
  806.       .SetPattern 1, .PaletteEntry(pNum), 0
  807.       If chkShowNumbers.Value = True Then
  808.          If optDecimal.Value = True Then
  809.             .Number = .PaletteEntry(pNum)
  810.          Else
  811.             .Text = Hex(.PaletteEntry(pNum))
  812.          End If
  813.       End If
  814.    End With
  815.       
  816. End Sub
  817. Private Sub txtColor_KeyPress(Index As Integer, KeyAscii As Integer)
  818. '' If the user types a value in the text box and then hits return
  819. '' we will set the palette entry. If they enter an invalid number
  820. '' we set it to zero. This is a programmer's tool so we can be terse.
  821.    Dim newNum%
  822.    If KeyAscii = 13 Then
  823.       newNum = Val(txtColor(Index).Text)
  824.       If newNum > -1 And newNum < 256 Then
  825.          txtColor(Index).Text = Str$(newNum)
  826.       Else
  827.          txtColor(Index).Text = 0
  828.       End If
  829.       Call SetColor
  830.    End If
  831. End Sub
  832. Private Sub txtFrom_KeyPress(Index As Integer, KeyAscii As Integer)
  833.    If KeyAscii = 13 Then
  834.       If Val(txtFrom(Index).Text) < 0 Or Val(txtFrom(Index).Text) > 255 Then
  835.          txtFrom(Index).Text = "0"
  836.       End If
  837.    End If
  838. End Sub
  839. Private Sub TxtTo_KeyPress(Index As Integer, KeyAscii As Integer)
  840.    If KeyAscii = 13 Then
  841.       If Val(TxtTo(Index).Text) < 0 Or Val(TxtTo(Index).Text) > 255 Then
  842.          TxtTo(Index).Text = "0"
  843.       End If
  844.    End If
  845. End Sub
  846.